#include "model.h"

#include "movableobject.h"
#include "spaceship.h"
using namespace spacedefender;

Model::Model()
{
	_playerShip = 0;
}

Model::~Model()
{	
	for(std::vector<MovableObject*>::iterator it = _objects.begin(); it != _objects.end(); it++)
	{
		delete *it;
		*it = 0;
	}
	
	_objects.clear();
	
	if(_playerShip)
	{
		delete _playerShip;
		_playerShip = 0;
	}
}

bool Model::Update()
{
	//TODO: can run this on lower frequency than the view. 
	//Add functionality for that here.
	return true;
}

bool Model::Initialize()
{
	//initialize ships and stuff that should be in the game here.
	
	Vector startPos(50.0f, 50.0f, 200.0f);
	_playerShip = new Spaceship();
	_playerShip->SetPosition(startPos);
	
	Vector meteoritePos(1.0f, 1.0f, 1.0f);
	_objects.push_back(new MovableObject("meteorite", meteoritePos));
	
	meteoritePos.i = 10.0f;
	_objects.push_back(new MovableObject("meteorite", meteoritePos));
	
	Vector lambdaShipPos(10.0f, 30.0f, 100.0f);
	_objects.push_back(new MovableObject("LambdaShip2", lambdaShipPos));
	
	Vector v  = lambdaShipPos-startPos;

	_playerShip->SetDirection(v);


	return true;
}

const Vector Model::GetPlayerShipDirection() const
{
	return _playerShip->GetDirection();
}

const Vector Model::GetPlayerShipPosition() const
{
	return _playerShip->GetPosition();
}

const std::vector<MovableObject*> Model::GetObjects() const
{
	return _objects;
}

MovableObject* Model::GetPlayerShip() const
{
	return _playerShip;
}
